package pub.gll.onepeas.todo;

import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import pub.gll.libaptannotation.Aspect;
import pub.gll.libaptannotation.Replace;
import pub.gll.onepeas.libbase.track.annotation.ViewExposure;
import pub.gll.onepeas.libbase.track.manager.KKVEManager;

/**
 * <pre>
 *     @author : whg
 *     @e-mail : guanhuawei@kkworld.com
 *     @time   : 2021/7/8 20:35
 *     @desc   : view全曝光时机hook
 *     解决问题：在实现view全曝光时，通过在decorview和contentview之前加入了一个kktrackerexposurelayout，通过这个view来获取页面子view的各个时机。
 *             现在hook的时机，就是其他地方直接加入到contentview之上的view，使它和kktrackerexposurelayout在一层。
 *             所以通过hook该时机，使其添加的view也称为kktrackerexposurelayout的子view。
 *     @version: 1.0
 * </pre>
 */
@Aspect
public class ViewExposureAop1 {

    @Replace(target = {"android.app.Activity.findViewById(I)Landroid/view/View;"}, extend = true, needSourceInfo = true, caller = {"^(pub.gll).*"})
    public static View hookFindViewById(Activity activity, int id, String source) {
        if (id != android.R.id.content) {
            return activity.findViewById(id);
        }
        ViewExposure annotation = activity.getClass().getAnnotation(ViewExposure.class);
        if (annotation == null) {
            return activity.findViewById(id);
        }
        ViewGroup container = activity.findViewById(id);
        return  KKVEManager.getInstance().getKkViewExposureLayout(container, activity);
    }

}
